package _10netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @description:
 * @author: wang zhen
 * @create: 2022-08-05 14:45
 */
public class WorkChannelHandler extends ChannelInboundHandlerAdapter {



    /**
     * 客户端与服务器建立连接后调用
     * @param ctx
     * @throws Exception
     */
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("有连接进入"+ctx.channel().id());
    }

    /**
     * 接收到客户端发来的数据后调用
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println(ctx.channel().id()+"发送数据"+msg.toString());
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        System.out.println(ctx.channel().id()+"发送数据完成");
    }
}
